package com.wkt.ggkt.exception;

import com.wkt.ggkt.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wangkt
 * @Describe
 * @date 2022/7/1 21:14
 */
@ControllerAdvice
public class GlobalException{

    /**
     * 全局异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail(null).message("执行了全局异常！");
    }

    /**
     * 自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler(GgktException.class)
    @ResponseBody
    public Result error(GgktException e){
        return Result.fail(null).code(e.getCode()).message(e.getMsg());
    }
}
